;xpMaker.au3
;Function xpMaker
;CREATED: Thomas Gilow		DATE: 20.08.2009
;NOTE: this function deletes and plows a field which was selected before,
;		giving 3XP and costs 30coins per turn

#Include <Misc.au3>

Func xpMaker($fvWinX,$fvWinY)

	Local $xpMakerGui,$deleteCoords[2], $plowCoords[2], $plowPlowCoords[2], $fieldCoords[2], $marketCoords[2], $mouseCoords[2], $soyCoords[2], $acceptCoords[2], $i, $exit, $sleep, $money, $xp

	$deleteCoords[0] = 733 + $fvWinX
	$deleteCoords[1] = 500 + $fvWinY

	$plowCoords[0] = 686 + $fvWinX
	$plowCoords[1] = 502 + $fvWinY

	$plowPlowCoords[0] = 682 + $fvWinX
	$plowPlowCoords[1] = 424 + $fvWinY

	$acceptCoords[0]= 300 + $fvWinX
	$acceptCoords[1]= 388 + $fvWinY

	$marketCoords[0] = 686 + $fvWinX
	$marketCoords[1] = 555 + $fvWinY

	$soyCoords[0] = 235 + $fvWinX
	$soyCoords[1] = 496 + $fvWinY

	$money=0
	$XP=0

	$exit=false

	$sleep=50

	while 1
		$mouseCoords = MouseGetPos()
		ToolTip("Markiere das XP Feld mit A", $mouseCoords[0]+5, $mouseCoords[1]+10)
		if _isPressed("41") Then
			$fieldCoords=$mouseCoords
			ExitLoop
		EndIf
	WEnd
	ToolTip("")
	while 1
		$mouseCoords = MouseGetPos()
		ToolTip("Starte XPmaker mit A", $mouseCoords[0]+5, $mouseCoords[1]+10)
		if _isPressed("41") Then
			ExitLoop
		EndIf
	WEnd
	ToolTip("")
	ToolTip("Der XP Maker arbeitet, beenden mit A",50,50)
	while 1
		ToolTip("Der XP Maker arbeitet, beenden mit A, Kosten:" & $money & ", XP: " &$xp,50,50)
		MouseClick("left",$plowCoords[0],$plowCoords[1])

		for $i=0 to $sleep
			if _isPressed("41") Then
				$exit=True
				ExitLoop
			Endif
			sleep(1)
		Next
		if $exit=true Then
			ExitLoop
		EndIf

		MouseClick("left",$plowPlowCoords[0],$plowPlowCoords[1])

		for $i=0 to $sleep
			if _isPressed("41") Then
				$exit=True
				ExitLoop
			Endif
			sleep(1)
		Next
		if $exit=true Then
			ExitLoop
		EndIf

		MouseClick("left",$fieldCoords[0],$fieldCoords[1])

		for $i=0 to $sleep+40
			if _isPressed("41") Then
				$exit=True
				ExitLoop
			Endif
			sleep(1)
		Next
		if $exit=true Then
			ExitLoop
		EndIf
		$money = $money + 15
		$xp=$xp+1

		MouseClick("left",$marketCoords[0],$marketCoords[1])

		for $i=0 to $sleep+200
			if _isPressed("41") Then
				$exit=True
				ExitLoop
			Endif
			sleep(1)
		Next
		if $exit=true Then
			ExitLoop
		EndIf


		MouseClick("left",$soyCoords[0],$soyCoords[1])

		for $i=0 to $sleep+40
			if _isPressed("41") Then
				$exit=True
				ExitLoop
			Endif
			sleep(1)
		Next
		if $exit=true Then
			ExitLoop
		EndIf


		MouseClick("left",$fieldCoords[0],$fieldCoords[1])

		for $i=0 to $sleep+40
			if _isPressed("41") Then
				$exit=True
				ExitLoop
			Endif
			sleep(1)
		Next
		if $exit=true Then
			ExitLoop
		EndIf
		$money = $money + 15
		$xp=$xp+2

		MouseClick("left",$deleteCoords[0],$deleteCoords[1])

		for $i=0 to $sleep
			if _isPressed("41") Then
				$exit=True
				ExitLoop
			Endif
			sleep(1)
		Next
		if $exit=true Then
			ExitLoop
		EndIf

		MouseClick("left",$fieldCoords[0],$fieldCoords[1])

		for $i=0 to $sleep+200
			if _isPressed("41") Then
				$exit=True
				ExitLoop
			Endif
			sleep(1)
		Next
		if $exit=true Then
			ExitLoop
		EndIf

		MouseClick("left",$acceptCoords[0],$acceptCoords[1])

		for $i=0 to $sleep
			if _isPressed("41") Then
				$exit=True
				ExitLoop
			Endif
			sleep(1)
		Next
		if $exit=true Then
			ExitLoop
		EndIf

	WEnd
	ToolTip("")

EndFunc
